﻿
using UnityEngine;

public static class XGameObject
{
    public static void Destroy(GameObject obj)
    {
        obj.SendMessage("XDestroy");
    }

#if UNITY_EDITOR
    [UnityEditor.MenuItem("GameObject/XDestroy")]
    public static void DestroyInScene() {
        var activeObj = UnityEditor.Selection.activeGameObject;
        Destroy(activeObj);
    }
#endif

    public static T AddMissingComponent<T>(this GameObject obj) where T: Component
    {
        var comp = obj.GetComponent<T>();
        if (comp == null)
            comp = obj.AddComponent<T>();
        return comp;
    }
}
